!(async function (){
    response=await taskObject.fetchtemplate(path='/api/user/course')
   
    await rendertable(data=response.data,domhtml='.course table tbody',domdata=['courseid','coursename','teacher','gender','messages'])
    dataform['statusdata']=[]
    let index=0
    for (const i of response.data){
         
        if(i.status){
            dataform['statusdata'].push(i)
            $(`.course tbody tr:eq(${index})`).append(`<td><button class="layui-btn  layui-btn-disabled" id=${i['courseid']} onclick=upstatus(this)>已选</button></td>`)
        }else{

            $(`.course tbody tr:eq(${index})`).append(`<td><button class="layui-btn-primary layui-bg-blue" id=${i['courseid']} onclick=upstatus(this)>选择</button></td>`)
       
        }
        index+=1
    }    
  
    
    await rendertable(data= dataform['statusdata'],domhtml='.statuscourse table tbody',domdata=['courseid','coursename','teacher','gender'])
}())
async function upstatus(even) { 
    
    let valueid=parseInt(even.id)
    let classlist=even.classList
    console.log(classlist[1]);
    let valuebool=true
    if (classlist[1]=='layui-btn-disabled'){
        valuebool=false
        layer.confirm('确认取消已选?', {
            btn: ['确定', '关闭'] //按钮
          }, async function(index,layero){
            valuebool=true
            response=await taskObject.fetchtemplate(path='/api/user/course',method='PUT',data={'courseid':valueid})
            if (response.code=200){
                layer.msg('操作成功',{icon:1,time:2000})
                setTimeout(()=>{
                    window.location.reload()
                },1500)
                return ;
            }
            
            layer.msg('操作失败',{icon:2,time:1700})
            layer.close(index)
          
          }, function(index,layero){
         
            layer.close(index)
          
          });
    }
    if(valuebool){
        response=await taskObject.fetchtemplate(path='/api/user/course',method='PUT',data={'courseid':valueid})
        if (response.code=200){
            layer.msg('操作成功',{icon:1,time:2000})
            setTimeout(()=>{
                window.location.reload()
            },1500)
            return ;
        }
        
        layer.msg('操作失败',{icon:2,time:1700})}

    
}

